import request from '@/utils/request'
import { Promise } from 'jszip/lib/external'

export function postRole(data) {
  return request({
    url: '/sys/role',
    method: 'post',
    data
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message))
}

// 公司设置删除角色
export function deleteRole(id) {
  return request({
    url: '/sys/role/' + id,
    method: 'delete'
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message))
}

// 公司设置编辑修改角色
export function putRole(params) {
  return request({
    url: '/sys/role/' + params.id,
    method: 'put',
    data: {
      ...params
    }
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message))
}
// 公司设置查询角色
export function getRole(id) {
  return request({
    url: '/sys/role/' + id,
  })
    .then(res => res.data.data)
    .catch(() => ({}))
}
// 获取权限列表
export function getPermission(params) {
  return request({
    url: 'sys/permission',
    data: params
  })
    .then(res => res.data.data)
    .catch(() => ({}))
}

// 给角色添加权限
export function putPermission(params) {
  return request({
    url: '/sys/role/assignPrem',
    method: 'put',
    data: {
      ...params
    }
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message))
}

export function getRoutes() {
  return request({
    url: '/vue-element-admin/routes',
    method: 'get'
  })
}

export function getRoles() {
  return request({
    url: '/vue-element-admin/roles',
    method: 'get'
  })
}

export function addRole(data) {
  return request({
    url: '/vue-element-admin/role',
    method: 'post',
    data
  })
}

export function updateRole(id, data) {
  return request({
    url: `/vue-element-admin/role/${id}`,
    method: 'put',
    data
  })
}

// export function deleteRole(id) {
//   return request({
//     url: `/vue-element-admin/role/${id}`,
//     method: 'delete'
//   })
// }
